#pragma once
#include <iostream>
#include <pthread.h>
#include <string>

typedef void (*CallBack)();  //定义函数指针

static int num = 1; //线程名编号

class Thread
{
private:
    static void *Routine(void *args)
    {
        Thread *t = static_cast<Thread *>(args);
        t->Entry();

        return nullptr;
    }

public:
    Thread(CallBack cb)
        : cb_(cb), IsRunning_(false), tid_(0), name_("")
    {
    }

    void run()
    {
        name_ = "Thread-" + std::to_string(num++);
        IsRunning_ = true;
        pthread_create(&tid_, nullptr, Routine, this);
    }

    void join()
    {
        pthread_join(tid_,nullptr);
    }

    void Entry()
    {
        cb_();
    }


private:
    pthread_t tid_;
    std::string name_;
    bool IsRunning_;

    CallBack cb_;   //回调函数
};